<template>
<!-- 5.9作业 -->
  <div>
    <form @submit.prevent='getBMI'>
      <label>姓名：</label>
      <input type="text" v-model="info.username"><br><br>

      <label>年龄：</label>
      <input type="number" v-model="info.age"><br><br>

      <label>身高：</label>
      <input type="text" v-model="info.height">(米)<br><br>

      <label>体重：</label>
      <input type="number" v-model="info.weight">(公斤)<br><br>

      <label>病史：</label>
      <input type="text" v-model="info.history"><br><br>

      <button>诊断</button>
    </form>

    <p v-show='flag'>患者{{info.username}}  的诊断结果：{{msg}}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
     info :{
     username:'',
     age:'',
     height:'',
     weight:'',
     history:'',
     },

     BMI:'',
     msg:'',
     flag: false
    }
  },
  methods: {
    getBMI() {
      this.flag = true
      this.BMI = this.info.weight / (this.info.height ^ 2)
      if(this.BMI < 18.5){
       this.msg = '体重过轻'
      }else if (this.BMI >= 18.5 && this.BMI < 24.9){
          this.msg = '健康'
      }else {
       this.msg = '体重过重'
      }
    }
  }
}
</script>